home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / mod2tutb.zip / REALMATH.MOD < prev    next >
Text File  |  1989-01-18  |  2KB  |  54 lines

  1.                                          (* Chapter 3 - Program 4 *)
  2. MODULE RealMath;
  3.  
  4. FROM InOut IMPORT WriteString, WriteLn;
  5. FROM RealInOut IMPORT WriteReal;
  6.  
  7. VAR Sum, Diff, Product, Div : REAL;
  8.     A, B    : REAL;
  9.     Inumber : INTEGER;
  10.     Cnumber : CARDINAL;
  11.  
  12. BEGIN
  13.    A := 3.234;                      (* Assigns a value          *)
  14.    B := A + 1.0123;                 (* Add a constant           *)
  15.    Sum := A + B;                    (* Add two variables        *)
  16.    Product := A * B;                (* Multiplication           *)
  17.    Div := A / B;                    (* Division                 *)
  18.    Diff := A - B;                   (* Subtraction              *)
  19.    A := (A + B)/(12. * A - B);      (* Multiple math expression *)
  20.  
  21.    WriteString("The REAL values are");
  22.    WriteReal(Sum,12);
  23.    WriteString("  ");
  24.    WriteReal(Diff,12);
  25.    WriteString("  ");
  26.    WriteReal(Product,12);
  27.    WriteString("  ");
  28.    WriteReal(Div,12);
  29.    WriteLn;
  30.  
  31.          (* Conversion between data types - illustration  *)
  32.  
  33.    Inumber := 15;          (* This is an INTEGER              *)
  34.    Cnumber := 333;         (* This is a CARDINAL              *)
  35.    A := FLOAT(Inumber);    (* INTEGER to REAL                 *)
  36.    B := FLOAT(Cnumber);    (* CARDINAL to REAL                *)
  37.    Inumber := TRUNC(Sum);  (* REAL to INTEGER                 *)
  38.    Cnumber := TRUNC(Sum);  (* REAL to CARDINAL                *)
  39.  
  40.    A := MIN(REAL);   (* This produces the smallest REAL *)
  41.    A := MAX(REAL);   (* This produces the largest REAL  *)
  42.  
  43. END RealMath.
  44.  
  45.  
  46.  
  47.  
  48. (* Result of execution
  49.  
  50. The REAL values are 7.4803E+000  -1.0123E+000   1.3733E+001   7.6160E-001
  51.  
  52. *)
  53.  
  54.